import Vue from 'vue'
import Vuex from 'vuex'
import * as api from '../requests/index.js'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		token:uni.getStorageSync('token'),
		logined:false,
		user:{data:null}
	},
	mutations: {
		SET_TOKEN:(state, val) => {
			uni.setStorageSync('token',val)
			state.logined = true
		},
		SET_LOGINED:(state,val)=>{
			state.logined = val
		},
		SET_USER:(state, val) => {
			state.user = val
		},
	},
	actions:{
		AC_GET_USERINFO({ commit }) {
			return api.info().then(res => {
				commit('SET_USER',res.data)
			})
		},
	}
})

export default store
